<template>
  <div class="contents" ref="toolbar">
    <div class="layer" @click="openLayers"> </div>
    <div class="radius-select" @click="openRadius"> </div>
    <Transition>
      <div class="layer-content" v-show="layersFlag">
        <layer-sources />
      </div>
    </Transition>
    <Transition>
      <div class="radius-content" v-show="radiusFlag">
        <radiusSetup />
      </div>
    </Transition>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import layerSources from './contentToolBar/layerSources.vue'
import radiusSetup from './contentToolBar/radiusSetup.vue'

const layersFlag = ref(false);
const radiusFlag = ref(false);
const toolbar = ref(null);

const openLayers = () => {
  layersFlag.value = !layersFlag.value
  radiusFlag.value = false
}
const openRadius = () => {
  radiusFlag.value = !radiusFlag.value
  layersFlag.value = false
}

onMounted(() => {
  window.addEventListener('click', (e) => {
    if ( toolbar.value &&!toolbar.value.contains(e.target)) {
      layersFlag.value = false
      radiusFlag.value = false
    }
  },false)
})
</script>

<style lang="scss" scoped>
.contents {
  position: relative;
}
.layer,
.radius-select {
  width: 50px;
  height: 50px;
  background-image: url(/static/icon/底图选择@1x.png);
  background-size: contain;
  background-position: center center;
  background-repeat: no-repeat;
  cursor: pointer;
}
.radius-select {
  background-image: url(/static/icon/范围半径@1x.png);
  background-size: contain;
  background-position: center center;
  background-repeat: no-repeat;
  cursor: pointer;
}
.layer-content {
  position: absolute;
  top: 0;
  left: -10px;
}
.layer-content {
  position: absolute;
  top: 5px;
  left: -410px;
  width: 400px;
  height: 280px;
  background-image: url(/static/icon/layer.png);
  background-size: 100% 100%;
  // padding: 15px;
  box-sizing: border-box;
}
.radius-content {
  position: absolute;
  top: 5px;
  left: -390px;
  width: 380px;
  height: 90px;
  background-image: url(/static/icon/radius.png);
  background-size: 100% 100%;
  padding: 10px 20px;
  box-sizing: border-box;
  color: #fff;
}
.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}
</style>